#include "speech_server.hpp"
#include "log.hpp"
#include <gflags/gflags.h>

DEFINE_bool(run_mode, false, "程序的运行模式, false-调试; true-发布;");
DEFINE_string(log_file, "", "发布模式下，用于指定日志的输出文件");
DEFINE_int32 (log_level, 0, "日志等级: 0-TRACE, 1-DEBUG, 2-INFO, 3-WARN, 4-ERROR, 5-FATAL");


DEFINE_string(app_id, "app_id", "百度语音识别的APPID");
DEFINE_string(api_key, "api_key", "百度语音识别的API Key");
DEFINE_string(secret_key, "secret_key", "百度语音识别的Secret Key");

DEFINE_string(etcd_host, "http://127.0.0.1:2379", "etcd的地址");
DEFINE_string(base_service, "/service", "服务注册的根目录");
DEFINE_string(instance_name, "/speech_service/instance1", "服务实例名称");
DEFINE_string(service_host, "127.0.0.1:10001", "语音服务外部访问地址");

DEFINE_uint32(port, 10001, "rpc服务器端口号");
DEFINE_int32(timeout_sec, -1, "rpc调用的超时时间");
DEFINE_uint32(num_threads, 4, "rpc服务器工作线程数量");

int main(int argn, char* argv[])
{
    google::ParseCommandLineFlags(&argn, &argv, true);
    init_logger(FLAGS_log_file, int_log_level_map(FLAGS_log_level), FLAGS_run_mode);
    SpeechServerBuilder builder;
    builder.make_asr_object(FLAGS_app_id, FLAGS_api_key, FLAGS_secret_key);
    builder.make_rpc_object(FLAGS_port, FLAGS_timeout_sec, FLAGS_num_threads);
    builder.make_reg_object(FLAGS_etcd_host, FLAGS_base_service + FLAGS_instance_name, FLAGS_service_host);
    SpeechServer::ptr speech_server = builder.build();
    if(!speech_server)
    {
        LOG_ERROR("创建语音服务失败");
        return -1;
    }
    speech_server->start();
    return 0;
}